const fp = require('lodash/fp')
const {Maybe, Container} = require('./support')
// 练习1
let maybe = Maybe.of([3, 4, 5]);
let ex1 = (val) => {
    return maybe.map((values) => fp.map(item => fp.add(val, item), values))
}
maybe = ex1(2)

// 练习2
let xs = Container.of(['do', 'ray',
    'me', 'fa', 'so', 'la', 'ti', 'do']);
let ex2 = () => {
    let first = xs.map(arr => fp.first(arr))
    return first
}
console.log(ex2())

// 练习3
let safeProp = fp.curry((x, o) => Maybe.of(o[x]));
let user = {id: 2, name: 'Albert'};
let ex3 = () => {
    let name = safeProp('name')(user)
    return fp.first(name._value)
}
console.log(ex3())

// 练习4
let ex4 = n => {
    let maybe = Maybe.of(n)
    return maybe.map(value => parseInt(value))._value
}
console.log(ex4(33.3))

